<template>
  <el-container>
    <el-header class="login-one">
        <br>
        <el-row>
            <el-col :span="8">
             <span>华清远见在线考试系统</span>
            </el-col>
            <el-col :span="8">&nbsp;</el-col>
            <el-col :span="8" align="right">
                <el-button type="success" icon="el-icon-setting" size="mini">修改密码</el-button>
                <el-button type="success" icon="el-icon-remove" size="mini">退出登录</el-button>
                <el-button type="success" icon="el-icon-user-solid" size="mini">admin</el-button>
            </el-col>
        </el-row>
    </el-header>
    <el-container>
      <el-aside width="240px">
        <el-menu
          class="el-menu-vertical-demo"
          router
          >
            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>试卷管理</span>
              </template>
                <el-menu-item index="/index/paperCreate">试卷生成</el-menu-item>
                <el-menu-item>试卷列表</el-menu-item>
                <el-menu-item>试卷统计</el-menu-item>

            </el-submenu>

          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>考试管理</span>
            </template>
              <el-menu-item index="/index/examCreate">分配考试</el-menu-item>
              <el-menu-item>考试列表</el-menu-item>
              <el-menu-item>考试统计</el-menu-item>
          </el-submenu>

          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>我的信息</span>
            </template>
            <el-menu-item index="/index/myExam">我的考试</el-menu-item>
            <el-menu-item index="/index/scoreCount">成绩统计</el-menu-item>
          </el-submenu>

        </el-menu>

      </el-aside>
      <el-main>
        <!--路由视图-->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>

</template>

<script>
    export default {
        name: "Index",
        data(){
          return{
             ws:null,
          }
        },
      created() {
        const self = this;
        const name = localStorage.getItem("name");
        //创建websocet对象，完成和服务段第一次握手
        this.ws = new WebSocket("ws://localhost:8003/kickServer/"+name);
        //服务端向客户端发送数据触发的事件
        //接受服务端的数据
        this.ws.onmessage=function (msg) {
          console.log("服务端发送的数据是:"+msg.data);
          if(msg.data=="已登录"){
            self.$alert("你的账号已经在其他地方登录，你被迫下线");
            //回到登录页面
            self.$router.push("/");
          }
        }
        this.ws.onclose=function () {
          console.log("1111")
        }


      }
    }
</script>

<style scoped>
  @import url('../../assets/css/index.css');
  .el-aside,.el-container{
        height:100%;
  }
  .el-aside{
     border: 1px solid #b6b6b6;

  }

</style>
